<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>添加项目部</title>
	<link rel="stylesheet" type="text/css" href="../../static/common.css"/>
	<link rel="stylesheet" type="text/css" href="../static/css/parameter.css" />
	
</head>
<body>
    <div class="rightBox">
		<!-- <nav class="nav clearfix">
			<li class="active">项目部分划分</li>
			<li >物资类别</li>
		</nav> -->
		<div class="contant clearfix" id="project">
			
			<!-- right -->
			<div class="cont_right " style="width: 100%;">
				<div class="right_top clearfix">
					
					<p class="blue fl" @click="subAdd(-1)" style="width: 65px;">导入</p>
					<p class="blue fl" style="margin-left: 20px;" @click="toUrl">取消</p>
					<ul class="fl clearfix" style="margin-left: 20px;">
						<input type="text" placeholder="项目部名称、项目部简称" class="fl" v-model="content" @keyup="enter($event)">
						<span class="fl" ></span>
					</ul>
					<p class="fl blue" @click="checkList">查询</p>
					<span class="err fl">11</span>
				</div>
				<table>
					<thead>
						<tr>
							<th @click="selectAll">全选</th>
							
							<th style="width: 18%;">项目部简称</th>
							<th>项目部全称</th>
							<th>操作</th>
						</tr>
					</thead>
					<tbody>
						<tr v-for="val,index in list" :id="val.projectId">
							<td><input type="checkbox" :checked="allSelect" /></td>
							
							<td>{{val.abbreviation}}</td>
							<td>{{val.projectName}}</td>
							<td @click="subAdd(val.projectId)">导入</td>
						</tr>
					</tbody>
				</table>
			</div>
		</div>
	</div>
</body>
</html>
<script src="../../static/js/jquery-1.8.3.js" type="text/javascript" charset="utf-8"></script>
<script src="../../static/dx.js" type="text/javascript" charset="utf-8"></script>
<script src="../../static/js/vue.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
	var uId = DX.getParam('id');
	var vm = new Vue({
		'el':'#project',
		mounted:function(){
			this.getList();
		},
		data:{
			'list':[],//列表数据
			'allSelect':false,//全选判断
			'content':'',//查询条件
		},
		methods:{
			getList:function(){
				var $this = this;
				var content = $this.content;
				DX.ajax_method({
					'url':'/user/project/getProjects',
					'type':'GET',
					'param':{'noUser':true,'content':content},
					'callBack':function(res){
						if(res.code == '200'){
							$this.list = res.data;
						}
					}
				});
			},
			selectAll:function(){//全选
				if(this.allSelect){
					this.allSelect = false;
				}else{
					this.allSelect = true;
				}
			},
			checkList:function(){//查询
				this.getList();
			},
			enter:function(event){//enter 回车查询
				
				if (event.keyCode == 13){
					event.returnValue=false;
					event.cancel = true;
					this.getList();
				}
			},
			subAdd:function(value){//提交
				var $this = this;
				var arr = [];
				
				if(value != -1){//单个提交
					arr.push(value);
				}else{//批量提交
					$.each($('.cont_right tr'),function(i,val){
						if($(this).find('input').prop('checked')){
							arr.push($(this).attr('id'));
						}
					});
				}
				if(arr.length <1){
					$('.err').show().text('请选择项目部');return;
				}
			
				DX.ajax_method({
					'type':'POST',
					'param':{'projectIds[]':arr,'uid':uId},
					'change':value.target,
					'url':'/user/project/assignProject',
					'callBack':function(res){
						if(res.code == '200'){
							$this.toUrl();
						}
					}
				});
			},
			toUrl:function(){
				value = 'parameter.html?id='+uId;
				window.location.href = value;
			}
		}
	})
</script>